package pl.lodz.p.browarex.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.springframework.stereotype.Repository;

import pl.lodz.p.browarex.base.interfaces.IBaseModel;

@Entity
@Table(name = "ORDER_PRODUCT_INFO")
@Repository
public class OrderProductInfo implements IBaseModel<Long> {

	private Long id;
	private String productCode;
	private Product product;
	private String productName;
	private Integer quantity;
	private Double price;
	private String stringPrice;

	// private Boolean confirmed;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "ORDER_PRODUCT_INFO_ID")
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(name = "PRODUCT_CODE", unique = false, nullable = false)
	public String getProductCode() {
		return productCode;
	}

	public void setProductCode(String productCode) {
		this.productCode = productCode;
	}

	@OneToOne
	@JoinColumn(name = "PRODUCT_ID", unique = false, nullable = false)
	public Product getProduct() {
		return product;
	}

	public void setProduct(Product product) {
		this.product = product;
		this.productCode = this.product.getProductID();
		this.productName = this.product.getProductName();
	}

	@Column(name = "PRODUCT_NAME", unique = false, nullable = false)
	public String getProductName() {
		return productName;
	}

	public void setProductName(String productName) {
		this.productName = productName;
	}

	@Column(name = "QUANTITY", unique = false, nullable = false)
	public Integer getQuantity() {
		return quantity;
	}

	public void setQuantity(Integer quantity) {
		this.quantity = quantity;
	}

	@Column(name = "PRICE", unique = false, nullable = false)
	public Double getPrice() {
		return price;
	}

	public void setPrice(Double price) {
		this.price = price;
		setStringPrice(Double.toString(price));
	}

	//
	// public Boolean getConfirmed() {
	// return confirmed;
	// }
	//
	// public void setConfirmed(Boolean confirmed) {
	// this.confirmed = confirmed;
	// }

	@Transient
	public String getStringPrice() {
		return stringPrice;
	}

	public void setStringPrice(String stringPrice) {
		this.stringPrice = String.format("%.2f",
				Double.parseDouble(stringPrice));
	}
}
